﻿@using CubicFWNet.Data.Models
@using CubicFWNet.Data.ViewModal
@model List<ArapView>
@{
    var operationName = ViewBag.OperationName;
    var operationTime = ViewBag.OperationTime;
    var financeNumber = ViewBag.FinanceNumber;

}
<section class="content-header">
    <h1>
        应付账款查询
        @*@if (Model != null)
            {
                if (Model.Status == -1)
                {
                    @Html.Raw("开票查询")
                }
                if (Model.Status == 1)
                {
                    @Html.Raw("售后查询")
                }
            }
            &nbsp;*@
    </h1>
    <ol class="breadcrumb">
        <li><a href="javascript:void(0);"><i class="fa fa-dashboard"></i>@Resources.Global.PageTitle</a></li>
        <li><a href="@Url.Action("Index", "Home")">首页</a></li>
        <li class="active"><a href="@Url.Action("YingFuQuery", "FinanceCost")">应付账款查询</a></li>
    </ol>
</section>
<section class="content">
    <div class="box box-solid">
        <!-- /.box-header -->
        <div class="box-body">
            <div class="row">
                @if (Model != null)
                {
                    <form class="form-horizontal" id="frmedit" action="@Url.Action("UpdateArap", "FinanceCost")" method="post">
                        <input type="hidden" id="FinanceNumber" name="FinanceNumber" value="@financeNumber" />
                        <div class="box-body">
                            <div id="json-content" class="col-md-12">
                                <table class="footable table table-stripped table-bordered table-hover" id="footable">
                                    <thead>
                                        <tr>
                                            <th data-sort-ignore="true">
                                                供应商
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true">
                                                类型
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true">
                                                发票号
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true">
                                                采购内容
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true">
                                                应付金额
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true" style="width: 133px;">
                                                累计金额
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true" style="width: 133px;">
                                                操作时间
                                            </th>
                                            <th data-hide="phone,table" data-sort-ignore="true">
                                                操作
                                            </th>
                                        </tr>
                                    </thead>
                                    <tbody id="data-content">
                                        @if (Model.Count > 0)
                                        {
                                            foreach (var item in Model)
                                            {
                                                var amount = (item.CostPrice * item.ShouldAmount).ToString("f2");
                                                <tr class="tr">
                                                    <td>
                                                        @item.CustomerName
                                                        <input type="hidden" class="form-control" id="Id" name="Id" value="@item.Id" readonly="readonly">
                                                        <input type="hidden" class="form-control" id="Status" name="Status" value="@item.Status" readonly="readonly">
                                                    </td>
                                                    <td>@item.ReconciliationTypeStr</td>
                                                    <td>@item.FinanceNumber</td>
                                                    <td>@item.ProductName</td>
                                                    <td>
                                                        @amount
                                                        <input type="hidden" class="form-control okeydown" id="ShouldMoney" name="ShouldMoney" value="@amount" readonly="readonly">
                                                    </td>
                                                    <td>
                                                        @item.TotalMoney
                                                    </td>
                                                    <td>
                                                        @if (item.CreateTimeIsNull != null)
                                                        {
                                                            @item.CreateTimeIsNull.Value.ToString("yyyy-MM-dd")
                                                        }
                                                    </td>
                                                    <td>
                                                        <span class="btn bg-blue btn-xs" onclick="caigouQueryInfo('@item.PurchaseComposeId')">查看</span>
                                                    </td>
                                                </tr>
                                            }
                                        }
                                    </tbody>
                                </table>
                            </div>
                            <div class="form-group col-md-12" style="height: 1px;"></div>
                            @*<div class="form-group col-md-6">
                                    <label class="col-sm-3 control-label">备注</label>
                                    <div class="col-sm-9">
                                        @if (Model.Status == -1)
                                        {
                                            <textarea class="form-control" rows="3" placeholder="请输入 ..." name="Memo" id="Memo"></textarea>
                                        }
                                        else
                                        {
                                            <textarea class="form-control" rows="3" placeholder="请输入 ..." name="Memo" id="Memo" readonly="readonly">@Model.Memo</textarea>
                                        }
                                    </div>
                                </div>*@
                            <div class="form-group col-md-12" style="height: 1px;"></div>

                            <div class="form-group col-md-6">
                                <label for="operationName" class="col-sm-3 control-label">操作人</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationName" name="operationName" value="@operationName" readonly="readonly">
                                </div>
                            </div>
                            <div class="form-group col-md-6">
                                <label for="operationTime" class="col-sm-3 control-label">日期</label>
                                <div class="col-sm-9">
                                    <input type="text" class="form-control" id="operationTime" name="operationTime" value="@operationTime" readonly="readonly">
                                </div>
                            </div>
                        </div>
                        <div class="box-footer" style="width: 80%; margin-left: 20px;">
                            <span id="historyBack" class="btn btn-primary submitbtn">返回</span>
                            @*<a class="btn btn-primary submitbtn" href="@Url.Action("ReceivableQuery", "FinanceCost")">返回</a>*@
                        </div>
                    </form>
                }
            </div>
        </div>
    </div>
</section>

<div id="loadingPage" style="display: none;">
    <div class="loading-shade"></div>
    <div class="loading-content" onclick="$.loading(false)">数据加载中，请稍后…</div>
</div>

@section Scripts{
    <script type="text/javascript">
        $(document).ready(function () {
            //日期控件
            $(".Timedatepicker").datepicker({
                autoclose: true,
                language: 'zh', //汉化
                format: "yyyy-mm-dd", //选择日期后，文本框显示的日期格式
                minView: "month"//选择日期后，不会再跳转去选择时分秒
            });

            $('#footable').footable();
        });

        var type = 1;

        function formsubmit(t) {
            type = t;
            $("#Type").val(t);
            $("#frmedit").submit();
        }

        $(document).on("keyup", ".itemActualMoney", function () {
            var itemMoney = $(this).val();//本次输入金额
            var cumulativeMoney = $(this).attr('data-cumulativeMoney');//累计金额
            var totalMoney = $(this).attr('data-totalMoney');//总金额
            //console.log(itemMoney + "+" + cumulativeMoney + "+" + totalMoney);
            if (isNaN(itemMoney)) {
                itemMoney = 0;
            }
            if (isNaN(cumulativeMoney)) {
                cumulativeMoney = 0;
            }
            if (isNaN(totalMoney)) {
                totalMoney = 0;
            }
            var sub = (((totalMoney / 1) - (cumulativeMoney / 1)) - (itemMoney / 1));
            if ((sub / 1) < 0) {
                $(this).val(((totalMoney / 1) - (cumulativeMoney / 1)));
            }

        });


        $(".okeydown").on("keydown", function () {
            var k = event.keyCode;
            if ((k <= 57 && k >= 48) || (k <= 105 && k >= 96) || (k == 8) || (k == 110) || (k == 190)) {
                return true;
            } else {
                return false;
            }
        });

        function getParam() {
            var postdata = [];
            //主键
            $("#json-content").find('.tr').each(function (r, i) { //input,select,textarea
                var postdataItem = {};
                $(i).find('input').each(function (m) {
                    var $this = $(this);
                    var value = $this.val();
                    var id = $this.attr('id');
                    if (id == "ActualMoney" && (isNaN(value) || value < 0 || value == "")) {
                        value = 0;
                    }
                    postdataItem[id] = value;
                });
                postdata.push(postdataItem);
            });
            return JSON.stringify(postdata);
        }

        $("#historyBack").click(function () {
            window.history.go(-1);  //返回上一页
            //window.history.back();  //返回上一页
        });

        function caigouQueryInfo(id) {
            var options = {
                id: null,
                title: '开票信息',
                width: "100%",
                height: "100%",
                url: "/Purchase/PurchaseLookInfoLayout?pcId=" + id,
                shade: 0.3,
                btn: ['返回'],
                btnclass: ['btn btn-danger'],
                callBack: null
            }
            $.modalOpen(options);
        }

    </script>
}